window.onload=function(){var content=document.getElementById("main-article");var topHeight=null;var scrollFunc=function(e){e=e||window.event;if(e.wheelDelta){if(e.wheelDelta>0){if(topHeight<=-50){topHeight+=50;content.style.top=topHeight+"px"}}if(e.wheelDelta<0){if(topHeight>=-(content.offsetHeight-(document.documentElement.clientHeight-90))){topHeight+=-50;content.style.top=topHeight+"px"}}}else{if(e.detail){if(e.detail>0){if(topHeight>=-(content.offsetHeight-(document.documentElement.clientHeight-90))){topHeight+=-50;content.style.top=topHeight+"px"}}if(e.detail<0){if(topHeight<=-50){topHeight+=50;content.style.top=topHeight+"px"}}}}};if(document.addEventListener){document.addEventListener("DOMMouseScroll",scrollFunc,false)}window.onmousewheel=document.onmousewheel=scrollFunc};
$(function (){
    var altsucess = document.getElementById("altsucess");
    $("#regbtnSub").click(function (){
        var username = $('#txtUserName').val(),
            pass = $('#txtUserPwd').val(),
            repass = $('#txtUserRePwd').val();
        if(username.length == 0)
        {
            altsucess.innerHTML = '用户名不能为空';
            return false;
        }
        if(pass.length == 0)
        {
            altsucess.innerHTML = '密码不能为空';
            return false;
        }
        if(repass.length == 0)
        {
            altsucess.innerHTML = '重复密码不能为空';
            return false;
        }
        if(pass != repass)
        {
            altsucess.innerHTML = '两次密码不一致';
            return false;
        }else{
            var userinfo = {
                name : username,
                password : pass
            };
            $.ajax({
                url:'/api/user/reg',
                type:'post',
                data: userinfo,
                dataType : "json",
                success:function (data){
                    if(data === 0){
                        altsucess.innerHTML = "用户名重复"
                    }else if(data === 1){
                        $('#txtUserName').val("");
                        $('#txtUserPwd').val("");
                        $('#txtUserRePwd').val("");
                        altsucess.innerHTML = "注册成功请点击登录：<a href='/login'>登录</a>";
                    }
                },
                error:function (){
                    altsucess.innerHTML = "(_　_)。゜zｚＺ没看清，请再输入一遍";
                }
            })
        }
    });
    $("#articlesubmit").click(function (){
        var commentnum = parseInt($("#article-comment div").length)-1;
        var comment = {
            comment : $("#comment").val(),
            user : $("#name").val(),
            email : $("#email").val(),
            id : $("#articletitle").data("id"),
            num :  commentnum
        };
        $.ajax({
            url:'/api/article',
            type:'post',
            data: comment,
            dataType : "json",
            success:function (data){
                if(data.code == 1){
                    $("#comment").val("");
                    $("#name").val("");
                    $("#email").val("");
                    $(".pinglun").after("<div>用户："+ data.name +"&nbsp;&nbsp;&nbsp;&nbsp;邮箱：<br>评论："+comment.comment+"<br><br></div>")
                }
            },
            error:function (){
                altsucess.innerHTML = "(_　_)。゜zｚＺ没看清，请再输入一遍";
            }
        })
    })
});